package dao;

import entities.Channel;

import javax.ejb.Local;
import javax.ejb.Stateless;
import java.util.List;

/**
 * Channel DAO Layer class
 * User: kaiser
 * Date: 7/31/13
 * Time: 9:15 PM
 */
@Stateless
@Local
public class ChannelDAO extends DAO<Channel> {

    @Override
    public List<Channel> getAll() {
        return getEntityManager().createQuery("SELECT c FROM Channel c").getResultList();
    }

    /**
     * Check by name is channel exist DB
     *
     * @param name channel name
     * @return true if exist
     */
    public boolean isExist(String name) {
        return getByName(name) != null;
    }

    /**
     * Getting Channel entity by name
     *
     * @param name channel name
     * @return channel entity if exist otherwise null
     */
    public Channel getByName(String name) {
        return getEntityManager().find(Channel.class, name);
    }
}
